package com.ruoyi.system.https.bo;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.ruoyi.system.domain.OrderqaInfo;
import com.ruoyi.system.domain.SapData;
import lombok.Data;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@Log4j2
@JacksonXmlRootElement(localName = "Envelope", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
@ToString
public class ZMES_GET_PWOQA_REPONSE {

    @JacksonXmlProperty(localName = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
    private ZMES_GET_PWOQA_Body body;

    public ZMES_GET_PWOQA_Body getBody() {
        return body;
    }

    public void setBody(ZMES_GET_PWOQA_Body body) {
        this.body = body;
    }
    @ToString
    public static class ZMES_GET_PWOQA_Body{
        @JacksonXmlProperty(localName = "ZmesGetPwoqaResponse", namespace = "urn:sap-com:document:sap:soap:functions:mc-style")
        private ZmesGetPwoqaResponse zmesGetPwoqaResponse;

        // Getters and Setters
        public ZmesGetPwoqaResponse getZmesGetPwoqaResponse() {
            return zmesGetPwoqaResponse;
        }
        public  void setZmesGetPwoqaResponse( ZmesGetPwoqaResponse zmesGetPwoqaResponse){
            this.zmesGetPwoqaResponse=  zmesGetPwoqaResponse;
        }
    }
    @ToString
    public static class ZmesGetPwoqaResponse {

        @JacksonXmlProperty(localName = "Pwoqa")
        private Pwoqa pwoqa;

        // Getters and Setters
        public Pwoqa getPwoqa() {
            return pwoqa;
        }

        public void setPwoi(Pwoqa pwoqa) {
            this.pwoqa = pwoqa;
        }
    }
    @ToString
    public static class Pwoqa {

        @JacksonXmlElementWrapper(useWrapping = false)
        @JacksonXmlProperty(localName = "item")
        private List<Item> items;

        // Getters and Setters
        public List<Item> getItems() {
            return items;
        }

        public void setItems(List<Item> items) {
            this.items = items;
        }
    }
    @Data
    @ToString
    public static class Item{
        @JacksonXmlProperty(localName = "Aufnr")
        private String Aufnr;
        @JacksonXmlProperty(localName = "Werks")
        private String Werks;
        @JacksonXmlProperty(localName = "Plnbez")
        private String Plnbez;
        @JacksonXmlProperty(localName = "Maktx")
        private String Maktx;
        @JacksonXmlProperty(localName = "Kurztext")
        private String Kurztext;
        @JacksonXmlProperty(localName = "Toleranzun")
        private String Toleranzun;
        @JacksonXmlProperty(localName = "Toleranzob")
        private String Toleranzob;
        @JacksonXmlProperty(localName = "Masseinhsw")
        private String Masseinhsw;
        @JacksonXmlProperty(localName = "Msehl")
        private String Msehl;
        @JacksonXmlProperty(localName = "PanelPreparation")
        private String PanelPreparation;

    }
    //对象映射
    public static List<OrderqaInfo> bodyToOrderqaInfo(ZMES_GET_PWOQA_REPONSE zmesGetPwoqaReponse){
        List<OrderqaInfo> orderqaInfos = new ArrayList<>();
        List<Item> items = zmesGetPwoqaReponse.getBody().getZmesGetPwoqaResponse().getPwoqa().getItems();
        for (Item item : items) {
            if(StringUtils.isNotBlank(item.getAufnr() )){
                OrderqaInfo orderqaInfo = new OrderqaInfo();
                orderqaInfo.setOrderNo(item.getAufnr());
                orderqaInfo.setPlant(item.getWerks());
                orderqaInfo.setMaterial(item.getPlnbez());
                orderqaInfo.setMaterialDesc(item.getMaktx());
                orderqaInfo.setItemSpec(item.getKurztext());
                orderqaInfo.setLower(item.getToleranzun());
                orderqaInfo.setUpper(item.getToleranzob());
                orderqaInfo.setUom(item.getMasseinhsw());
                orderqaInfo.setUnit(item.getMsehl());
                orderqaInfo.setPanel(item.getPanelPreparation());
                orderqaInfo.setIsEnable(1l);
                orderqaInfo.setCreateTime(LocalDateTime.now());
                orderqaInfos.add(orderqaInfo);
            }
        }
        return orderqaInfos;
    }
}
